package thread;

public class DaemonThreadDemo {
    public static void main(String[] args) {
        Thread rose = new Thread("rose:") {
            public void run() {
                for (int i = 0; i < 5; i++) {
                    System.out.println(getName() + "让我跳!让我跳!让我跳!");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
                System.out.println("啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊!");
                System.out.println("扑通!");

            }
        };

        Thread jake = new Thread("jake:") {
            public void run() {
                while (true) {
                    System.out.println(getName() + "你跳~我也跳!你跳~我也跳!你跳~我也跳!你跳~我也跳!你跳~我也跳!我也跳!我也跳!我也跳!");
                    try {
                        Thread.sleep(1001);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        rose.start();
        jake.setDaemon(true);//设置jake为守护线程
        jake.start();
      // while (true); //rose线程结束后如果主线程不结束，进程也不会结束，那么jake就不会被进程杀死也不会结束
    }
}
